package com.zblwyj.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfiguration {

    @Bean
    public Queue queue() {
        return new Queue("wfx-quence");
    }

    @Bean
    public Queue fanoutQuence() {
        return new Queue("wfx-fanout-quence");
    }
    /**
     * 声明交换机,fanout 类型(订阅模式)
     */
    @Bean
    public FanoutExchange fanoutExchange() {
        FanoutExchange fanoutExchange = new FanoutExchange("fanoutExchange");
        return fanoutExchange;
    }
    /**
     * 将队列和交换机绑定
     */
    @Bean
    public Binding bindingFanoutExchange(Queue fanoutQuence, FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(fanoutQuence).to(fanoutExchange);
    }

    @Bean
    public Queue directQuence1() {
        return new Queue("wfx-direct-quence1");
    }
    @Bean
    public Queue directQuence2() {
        return new Queue("wfx-direct-quence2");
    }
    /**
     * 声明交换机,direct 类型(路由模式)
     */
    @Bean
    public DirectExchange directExchange() {
        DirectExchange directExchange = new DirectExchange("directExchange");
        return directExchange;
    }
    /**
     * 将队列和交换机绑定
     */
    @Bean
    public Binding bindingDirectExchange(Queue directQuence1, DirectExchange directExchange) {
        return BindingBuilder.bind(directQuence1).to(directExchange).with("rk1");
    }

    @Bean
    public Binding bindingDirectExchange2(Queue directQuence2, DirectExchange directExchange) {
        return BindingBuilder.bind(directQuence2).to(directExchange).with("rk2");
    }

}

